package com.itheima.d06_api_object;

/**
 * 目标：掌握Object提供的常用方法
 */
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {
        Pig pig = new Pig("南京红姐", 38, "男");
        Pig pig2 = new Pig("南京红姐", 38, "男");

        //1.Object的toString方法，获取当前对象的内存地址
        String data = pig.toString();


        //2.Object的equals方法，比较两个对象变量中存储的数据（地址）是否一直
        boolean result = pig.equals(pig2);

        System.out.println("toString:"+pig/*.toString()*/);
        System.out.println("equals:"+result);


        //3.Object的clone方法，克隆对象
        //clone()方法被修饰符protected修饰，只能在同一个包中，或者子类中访问
        for (int i = 0; i < 100; i++) {
            Pig pig3 = (Pig) pig.clone();
            System.out.println(pig3);
        }

    }
}
